from PySide6.QtWidgets import *
from PySide6.QtCore import *
from PySide6.QtUiTools import QUiLoader

class DialogFind(QDialog):
    Signal_find = Signal(str)
    def __init__(self, parent=None):
        super().__init__(parent,Qt.Dialog)
        self.setAttribute(Qt.WA_DeleteOnClose)  

        self.ui_init()
        self.connect_init()
        
        

    def ui_init(self):
        if not self.parent():
            return
        # 获取主窗口位置

        loader = QUiLoader()
        self.ui = loader.load("ui/dialog_find.ui", self)

        self.ui.setParent(self)
        self.setLayout(self.ui.layout())
        self.setGeometry(self.ui.geometry())
        self.setWindowTitle("洛克王国宠物大全（单机版）")
        self.setStyleSheet(self.ui.styleSheet())

        main_window_size = self.parent().size()
        desktop = QApplication.primaryScreen().availableGeometry()
        w, h = desktop.width(), desktop.height()
        self.move(w//2 - main_window_size.width()//2, h//2 - main_window_size.height()//2)


    def connect_init(self):

        self.ui.pb_search.clicked.connect(self.select_find)
        
    def select_find(self):
        self.Signal_find.emit(self.ui.le_search.text())
        self.close()


    def closeEvent(self,event):
        self.Signal_find.emit("取消")
        event.accept()